/*********************\
* Author:Dzlua
* QQ:505544956
* Time:2017/03/15
\**********************/
#ifndef __SD_WINDOWBASE_H__
#define __SD_WINDOWBASE_H__
#pragma once
namespace DuiLib {

class UILIB_API SDWindowBase
{
public:
    SDWindowBase() : m_pm(NULL) {}
    CPaintManagerUI* GetPaintManager();
public:
    bool IsUpdateNeeded() const;
    void NeedUpdate();
    void Invalidate();
    void Invalidate(RECT& rcItem);

    LPCTSTR GetName() const;
    HDC GetPaintDC() const;
    HWND GetPaintWindow() const;
    HWND GetTooltipWindow() const;
    /*int GetTooltipWindowWidth() const;
    void SetTooltipWindowWidth(int iWidth);
    int GetHoverTime() const;
    void SetHoverTime(int iTime);*/

    POINT GetMousePos() const;
    SIZE GetClientSize() const;
    SIZE GetInitSize();
    void SetInitSize(int cx, int cy);
    RECT& GetSizeBox();
    void SetSizeBox(RECT& rcSizeBox);
    RECT& GetCaptionRect();
    void SetCaptionRect(RECT& rcCaption);
    SIZE GetRoundCorner() const;
    void SetRoundCorner(int cx, int cy);
    SIZE GetMinInfo() const;
    void SetMinInfo(int cx, int cy);
    SIZE GetMaxInfo() const;
    void SetMaxInfo(int cx, int cy);
    bool IsShowUpdateRect() const;
    void SetShowUpdateRect(bool show);

    BYTE GetOpacity() const;
    void SetOpacity(BYTE nOpacity);

    bool IsLayered();
    void SetLayered(bool bLayered);
    RECT& GetLayeredInset();
    void SetLayeredInset(RECT& rcLayeredInset);
    BYTE GetLayeredOpacity();
    void SetLayeredOpacity(BYTE nOpacity);
    //LPCTSTR GetLayeredImage();
    //void SetLayeredImage(LPCTSTR pstrImage);

    CShadowUI* GetShadow();

    bool ShowCaret(bool bShow);
    bool SetCaretPos(CRichEditUI* obj, int x, int y);
    CRichEditUI* GetCurrentCaretObject();
    bool CreateCaret(HBITMAP hBmp, int nWidth, int nHeight);
    void DrawCaret(HDC hDC, const RECT& rcPaint);
    
    void SetUseGdiplusText(bool bUse);
    bool IsUseGdiplusText() const;
    void SetGdiplusTextRenderingHint(int trh);
    int GetGdiplusTextRenderingHint() const;

    bool IsForceUseSharedRes() const;
    void SetForceUseSharedRes(bool bForce);

    void DeletePtr(void* ptr);

    DWORD GetDefaultDisabledColor() const;
    void SetDefaultDisabledColor(DWORD dwColor, bool bShared = false);
    DWORD GetDefaultFontColor() const;
    void SetDefaultFontColor(DWORD dwColor, bool bShared = false);
    DWORD GetDefaultLinkFontColor() const;
    void SetDefaultLinkFontColor(DWORD dwColor, bool bShared = false);
    DWORD GetDefaultLinkHoverFontColor() const;
    void SetDefaultLinkHoverFontColor(DWORD dwColor, bool bShared = false);
    DWORD GetDefaultSelectedBkColor() const;
    void SetDefaultSelectedBkColor(DWORD dwColor, bool bShared = false);
    TFontInfo* GetDefaultFontInfo();
    void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
    DWORD GetCustomFontCount(bool bShared = false) const;
    void AddFontArray(LPCTSTR pstrPath);
    HFONT AddFont(int id, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
    HFONT GetFont(int id);
    HFONT GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
    int GetFontIndex(HFONT hFont, bool bShared = false);
    int GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic, bool bShared = false);
    void RemoveFont(HFONT hFont, bool bShared = false);
    void RemoveFont(int id, bool bShared = false);
    void RemoveAllFonts(bool bShared = false);
    TFontInfo* GetFontInfo(int id);
    TFontInfo* GetFontInfo(HFONT hFont);

    const TImageInfo* GetImage(LPCTSTR bitmap);
    const TImageInfo* GetImageEx(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, HINSTANCE instance = NULL);
    const TImageInfo* AddImage(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0, bool bUseHSL = false, bool bShared = false, HINSTANCE instance = NULL);
    const TImageInfo* AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha, bool bShared = false);
    void RemoveImage(LPCTSTR bitmap, bool bShared = false);
    void RemoveAllImages(bool bShared = false);

    void ReloadImages();

    const TDrawInfo* GetDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify);
    void RemoveDrawInfo(LPCTSTR pStrImage, LPCTSTR pStrModify);
    void RemoveAllDrawInfos();

    void AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList, bool bShared = false);
    LPCTSTR GetDefaultAttributeList(LPCTSTR pStrControlName) const;
    bool RemoveDefaultAttributeList(LPCTSTR pStrControlName, bool bShared = false);
    void RemoveAllDefaultAttributeList(bool bShared = false);

    void AddWindowCustomAttribute(LPCTSTR pstrName, LPCTSTR pstrAttr);
    LPCTSTR GetWindowCustomAttribute(LPCTSTR pstrName) const;
    bool RemoveWindowCustomAttribute(LPCTSTR pstrName);
    void RemoveAllWindowCustomAttribute();

    void AddStyle(LPCTSTR pName, LPCTSTR pStyle, bool bShared = false);
    LPCTSTR GetStyle(LPCTSTR pName) const;
    BOOL RemoveStyle(LPCTSTR pName, bool bShared = false);
    const CStdStringPtrMap& GetStyles(bool bShared = false) const;
    void RemoveAllStyle(bool bShared = false);

    const TImageInfo* GetImageString(LPCTSTR pStrImage, LPCTSTR pStrModify = NULL);

    bool InitDragDrop();
    virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium,DWORD *pdwEffect);

    bool AttachDialog(CControlUI* pControl);
    bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
    void ReapObjects(CControlUI* pControl);

    bool AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
    CStdPtrArray* GetOptionGroup(LPCTSTR pStrGroupName);
    void RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
    void RemoveAllOptionGroups();

    CControlUI* GetFocus() const;
    void SetFocus(CControlUI* pControl);
    void SetFocusNeeded(CControlUI* pControl);

    bool SetNextTabControl(bool bForward = true);

    bool SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse);
    bool KillTimer(CControlUI* pControl, UINT nTimerID);
    void KillTimer(CControlUI* pControl);
    void RemoveAllTimers();

    void SetCapture();
    void ReleaseCapture();
    bool IsCaptured();

    bool IsPainting();
    void SetPainting(bool bIsPainting);

    bool AddNotifier(INotifyUI* pControl);
    bool RemoveNotifier(INotifyUI* pControl);   
    void SendNotify(TNotifyUI& Msg, bool bAsync = false);
    void SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam = 0, LPARAM lParam = 0, bool bAsync = false);

    bool AddPreMessageFilter(IMessageFilterUI* pFilter);
    bool RemovePreMessageFilter(IMessageFilterUI* pFilter);

    bool AddMessageFilter(IMessageFilterUI* pFilter);
    bool RemoveMessageFilter(IMessageFilterUI* pFilter);

    int GetPostPaintCount() const;
    bool IsPostPaint(CControlUI* pControl);
    bool AddPostPaint(CControlUI* pControl);
    bool RemovePostPaint(CControlUI* pControl);
    bool SetPostPaintIndex(CControlUI* pControl, int iIndex);

    int GetPaintChildWndCount() const;
    bool AddPaintChildWnd(HWND hChildWnd);
    bool RemovePaintChildWnd(HWND hChildWnd);

    void AddDelayedCleanup(CControlUI* pControl);

    bool AddTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
    bool RemoveTranslateAccelerator(ITranslateAccelerator *pTranslateAccelerator);
    bool TranslateAccelerator(LPMSG pMsg);

    CControlUI* GetRoot() const;
    CControlUI* FindControl(POINT pt) const;
    CControlUI* FindControl(LPCTSTR pstrName) const;
    CControlUI* FindSubControlByPoint(CControlUI* pParent, POINT pt) const;
    CControlUI* FindSubControlByName(CControlUI* pParent, LPCTSTR pstrName) const;
    CControlUI* FindSubControlByClass(CControlUI* pParent, LPCTSTR pstrClass, int iIndex = 0);
    CStdPtrArray* FindSubControlsByClass(CControlUI* pParent, LPCTSTR pstrClass);

    CDPI* GetDPIObj();
    void ResetDPIAssets();
    void RebuildFont(TFontInfo* pFontInfo);
    void SetDPI(int iDPI);

    bool MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
    bool PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);
    void UsedVirtualWnd(bool bUsed);
protected:
    CPaintManagerUI *m_pm;
};

}
#endif //__SD_WINDOWBASE_H__